package com.cl.code.database.mybatis.log;

import org.apache.ibatis.logging.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * sql日志
 *
 * @author chengliang
 * @since 1.0.0
 */
public class CLMybatisLog implements Log {

    private final Logger log;

    public CLMybatisLog(String clazz) {
        log = LoggerFactory.getLogger(clazz);

//        if (logger instanceof LocationAwareLogger) {
//            try {
//                // check for slf4j >= 1.6 method signature
//                logger.getClass().getMethod("log", Marker.class, String.class, int.class, String.class, Object[].class,
//                        Throwable.class);
//                log = new Slf4jLocationAwareLoggerImpl((LocationAwareLogger) logger);
//                return;
//            } catch (SecurityException | NoSuchMethodException e) {
//                // fail-back to Slf4jLoggerImpl
//            }
//        }
//
//        // Logger is not LocationAwareLogger or slf4j version < 1.6
//        log = new Slf4jLoggerImpl(logger);
    }

    @Override
    public boolean isDebugEnabled() {
        return log.isInfoEnabled();
    }

    @Override
    public boolean isTraceEnabled() {
        return log.isTraceEnabled();
    }

    @Override
    public void error(String s, Throwable e) {
        log.error(s, e);
    }

    @Override
    public void error(String s) {
        log.error(s);
    }

    @Override
    public void debug(String s) {
        log.info(s);
    }

    @Override
    public void trace(String s) {
        log.trace(s);
    }

    @Override
    public void warn(String s) {
        log.warn(s);
    }

}
